import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.AirlineReservationServiceProxy;
import bean.Person;
import constants.AirlineReservationServiceConstants;


public class AuthenticateUserServlet extends HttpServlet{

	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		AirlineReservationServiceProxy proxy = new AirlineReservationServiceProxy(
				AirlineReservationServiceConstants.SERVICE_URL);
			
		String username = req.getParameter("username").trim();
		String password = req.getParameter("password").trim();
		
		Person person = proxy.authenticateUser(username, password);
		
		System.out.println("Inside AuthenticateUserServlet....."+ person);
		
		if(person!=null && person.getUserName()!=null){
			HttpSession session = req.getSession();
			req.getSession().setAttribute("user", person);
			
			resp.setContentType("text");
			resp.getWriter().print("true");
			
			
		}else{
			
			resp.setContentType("text");
			resp.getWriter().print("false");
			req.setAttribute("Error", "Incorrect Username/password");
			
			
		}
		
		
	}
}
